[Add a label to a Node]
$ kubectl get nodes --show-labels
NAME      STATUS    ROLES    AGE     VERSION        LABELS
worker0   Ready     <none>   1d      v1.13.0        ...,kubernetes.io/hostname=worker0
worker1   Ready     <none>   1d      v1.13.0        ...,kubernetes.io/hostname=worker1
worker2   Ready     <none>   1d      v1.13.0        ...,kubernetes.io/hostname=worker2

[Choose one of the nodes, and add a label to it]
$ kubectl label nodes NODE_NAME disktype=ssd

[Verify that chosen node has a disktype=ssd label]
$ kubectl get nodes --show-labels
NAME      STATUS    ROLES    AGE     VERSION        LABELS
worker0   Ready     <none>   1d      v1.13.0        ...,disktype=ssd,kubernetes.io/hostname=worker0
worker1   Ready     <none>   1d      v1.13.0        ...,kubernetes.io/hostname=worker1
worker2   Ready     <none>   1d      v1.13.0        ...,kubernetes.io/hostname=worker2

So can see that the worker0 node has a disktype=ssd label.


➤ Schedule a Pod using required node affinity

Pod that has a requiredDuringSchedulingIgnoredDuringExecution node affinity,disktype: ssd. 
This means that the pod will get scheduled only on a node that has a disktype=ssd label.

[Create a Pod that is scheduled onto chosen node]
$ kubectl apply -f nodeAffinity_1.yaml
$ kubectl apply -f https://k8s.io/examples/pods/pod-nginx-required-affinity.yaml

[Verify that the pod is running on chosen node]
$ kubectl get pods --output=wide
NAME     READY     STATUS    RESTARTS   AGE    IP           NODE
nginx    1/1       Running   0          13s    10.200.0.4   worker0


➤ Schedule a Pod using preferred node affinity

Pod that has a preferredDuringSchedulingIgnoredDuringExecution node affinity,disktype: ssd. 
This means that the pod will prefer a node that has a disktype=ssd label.

[create a Pod that is scheduled onto chosen node]
$ kubectl apply -f nodeAffinity_2.yaml
$ kubectl apply -f https://k8s.io/examples/pods/pod-nginx-preferred-affinity.yaml

[Verify that the pod is running on chosen node]
$ kubectl get pods --output=wide
NAME     READY     STATUS    RESTARTS   AGE    IP           NODE
nginx    1/1       Running   0          13s    10.200.0.4   worker0
